package org.lyy.controller;

import org.lyy.entity.User;
import org.lyy.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@CrossOrigin//跨域
@RestController//@Controller+@ResponseBody
@RequestMapping("/admin/")
//@Slf4j
public class UserController{

    @Autowired
    private UserService userService;
    @RequestMapping("user")
    public Map<String, Object> loginPost(String namePost, String passwordPost){
        User user = new User();
        System.out.println("user"+namePost);
        user.setName(namePost);
        user.setPassword(passwordPost);
        List<User> u = userService.queryAll();
        System.out.println("查询到的数值为");
        Map<String, Object> retMap = new HashMap<>();
        for (User user1 : u) {
            //查询
            //System.out.println(user1.getName() + " " + user1.getPassword());
            if(user1.getName().equals(namePost) && user1.getPassword().equals(passwordPost)){
                System.out.println("successful");
                retMap.put("namePost", namePost+"-val");
                retMap.put("psd", passwordPost+"-val");
                retMap.put("msg","success-val");
                retMap.put("who",namePost);
            }
        }
        return retMap;
    }
}
